# @Time : 2025/3/1 20:30
# @Author : Fioman
# @Phone : 13149920693
"""
测试角度正负,小铡刀和大铡刀的夹角的正负问题
"""
import os

import cv2 as cv

from vision_process.vision_helper import get_two_line_angle

horMidLeftP = (91, 960)
horMidRightP = (1586, 923)
verMidTopPUp = (500, 285)  # 往左边倾斜
verMidBottomPUp = (835, 941)
angleUp = get_two_line_angle((verMidTopPUp, verMidBottomPUp), (horMidLeftP, horMidRightP))

print("angleUp = {}".format(angleUp))


# 将4拼从横着的坐标编程两个双拼,从中间截开
def get_two_double_board_from_4p(image):
    """
        将4pin板从中间分隔成两幅图像,变成单拼板,然后位置又不变,其他地方填充为黑色
    """
    sliceY1 = int(image.shape[0] / 2 + 0.5) + 300
    sliceY2 = int(image.shape[0] / 2 + 0.5) - 200
    imageUp = image.copy()
    imageUp[sliceY1:, :] = 0
    imageDown = image.copy()
    imageDown[:sliceY2, :] = 0
    return imageUp, imageDown


if __name__ == "__main__":
    imageDir = r"F:\raw_2025\zhanhua\4pin\ok"
    for root, dirs, files in os.walk(imageDir):
        if root != imageDir:
            continue
        for file in files:
            if file.endswith(".bmp"):
                imagePath = os.path.join(root, file)
                image = cv.imread(imagePath)
                imageUp, imageDown = get_two_double_board_from_4p(image)
                cv.imwrite(os.path.join(root, file.replace(".bmp", "_up.bmp")), imageUp)
                cv.imwrite(os.path.join(root, file.replace(".bmp", "_down.bmp")), imageDown)
